
var WindMenu = new Object();

WindMenu.createModel = function() {
	var model = new Object();
	
	model.getChildren = function(path) {
		var children = 0;
		if(path==null) {
			children = 3;
		} else {
			if(path.length==1) {
				children = 3;
			} else if(path.length==2) {
				children = 3;
			}
		}
		return children;
	}

	model.getContent = function(path) {
		var content = null;
		if(path!=null) {
			if(path.length==1) {
				var label = WindLabel.createView();
				label.setText("Node " + path[0]);
				content = label;
			} else if (path.length==2) {
				var label = WindLabel.createView();
				label.setText("Node " + path[0] + " " + path[1]);
				content = label;
			} else if (path.length==3) {
				var label = WindLabel.createView();
				label.setText("Node " + path[0] + " " + path[1] + " " + path[2]);
				content = label;
			}
		}
		return content;
	}
	
	return model;
}

WindMenu.createView = function(model) {
	var menu = new WindView();
	menu.setCssClass("WindMenu");
	
	var timer = null;
	menu.onMouseOut = function(e) {
		timer = window.setTimeout(function(e){WindMenu.hide(menu)}, 500); 
	}
	menu.onMouseOver = function(e) {
		if(timer!=null) {
			window.clearTimeout(timer);
		}
	}
	
	if(model==null) {
		model = WindMenu.createModel();
	}
	
	var children = model.getChildren();
	var path = new Array();
	for(var i=0; i<children; i++) {
		path.length = 1;
		path[0] = i;
		var item = WindMenu.createItemView(model, path);
		menu.addView(item);
	}
	
	return menu;
}

WindMenu.createContextMenuView = function(model, e) {
	var menu = WindMenu.createView(model);
	menu.setX(e.clientX -10 ) ;
	menu.setY(e.clientY + document.body.scrollTop - 10);
	return menu;
}

WindMenu.hide = function(menu) {
	WindWindow.removeView(menu);
}

WindMenuItemModel = function() {
}

WindMenuItemModel.prototype.getText = function() {
	return this.text;
}

WindMenuItemModel.prototype.setText = function(text) {
	this.text = text;
}

WindMenuItemModel.prototype.getAction = function() {
	return this.action;
}

WindMenuItemModel.prototype.setAction = function(action) {
	this.action = action;
}


WindMenu.createItemView = function(model, path) {
	var itemModel = model.getItem(path);

	var itemView = new WindView();
	itemView.setCssClass("WindMenuItem");
	itemView.setText(itemModel.getText());
	itemView.onClick = itemModel.getAction();
	
	return itemView;
}
